<template>
  <page-header-wrapper>
    <!-- <application-search
      :filterFields="['BeviewResult']"
      @search="handleSearch"
      @reset="handleReset"
    ></application-search> -->
    <a-card :bordered="false">
      <div class="table-header m-b-24"></div>
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        showPagination="auto"
        :scroll="{ x: true }"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <!-- <div slot="tabAction">
          <buttonSelect
            v-model="typeSelect"
            :options="[
              { value: '', label: '全部' },
              { value: '符合', label: '符合' },
              { value: '不符合', label: '不符合' },
              { value: '未审核', label: '未审核' },
            ]"
            @change="handleButtonSelectChange"
          />
        </div> -->
      </s-table>
    </a-card>
    <!-- <print :visible.sync="visiblePrint" :data.sync="printData"></print> -->
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis, buttonSelect, applicationSearch } from '@/components'
import { getProposerList } from '@/api/common'
// import print from './components/print.vue'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    buttonSelect,
    applicationSearch,
    // print,
  },
  computed: {
    textColor() {
      return function (text) {
        const classMap = new Map([
          ['符合', 'text-success'],
          ['不符合', 'text-error'],
          ['未审核', 'text-warning'],
        ])
        return classMap.get(text)
      }
    },
  },
  data() {
    this.$eventBus.$on('primaryAuditRefresh', () => {
      this.$refs.table.refresh()
    })
    return {
      typeSelect: '',
      visiblePrint: false,
      printData: {},
      queryParam: {
        UserID: this.$store.getters.userid,
        Mode: 'SQPhone',
        strContent: {},
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          customRender: (text, record, index) => <span>{index + 1}</span>,
        },
        {
          title: '申请编号',
          align: 'center',
          dataIndex: 'ApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          dataIndex: 'IDCard',
        },
        // {
        //   title: '电话号码',
        //   align: 'center',
        //   dataIndex: 'Phone',
        // },
        {
          title: '所属社区',
          align: 'center',
          dataIndex: 'TownshipName',
        },
        {
          title: '保障人数',
          align: 'center',
          dataIndex: 'CityVfyNumber',
        },
        {
          title: '保障方式',
          align: 'center',
          dataIndex: 'ApplyClass',
        },
        {
          title: '补贴方式',
          align: 'center',
          dataIndex: 'CityVfyAssign',
        },
        {
          title: '社区审核状态',
          align: 'center',
          fixed: 'right',
          dataIndex: 'BeviewResult',
          customRender: (text) => {
            let value = '未审核'
            if (!this.$isEmpty(text)) {
              value = text
            }
            return <span class={this.textColor(value)}>{value}</span>
          },
        },
        {
          title: '区级审核状态',
          align: 'center',
          fixed: 'right',
          dataIndex: 'VerifyResult',
          customRender: (text) => {
            let value = '未审核'
            if (!this.$isEmpty(text)) {
              value = text
            }
            return <span class={this.textColor(value)}>{value}</span>
          },
        },
        {
          title: '市级审核状态',
          align: 'center',
          fixed: 'right',
          dataIndex: 'CityVfyResult',
          customRender: (text) => {
            let value = '未审核'
            if (!this.$isEmpty(text)) {
              value = text
            }
            return <span class={this.textColor(value)}>{value}</span>
          },
        },
        {
          title: '审批结果',
          align: 'center',
          fixed: 'right',
          dataIndex: 'CityRfyResult',
          customRender: (text) => {
            let value = '未审核'
            if (!this.$isEmpty(text)) {
              value = text
            }
            return <span class={this.textColor(value)}>{value}</span>
          },
        },
        {
          title: '操作',
          align: 'center',
          fixed: 'right',
          width: 240,
          customRender: (text, record, index) => {
            return (
              <div>
                <y-button type="link" onClick={this.handleDetail.bind(this, record.ID)}>
                  查看
                </y-button>
                <y-button type="link" onClick={this.handleDetailEdit.bind(this, record.ID)}>
                  修改电话号码
                </y-button>
              </div>
            )
          },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        requestParameters.strContent.BeviewResult = this.typeSelect
        return getProposerList(requestParameters).then((res) => {
          return res
        })
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.$refs.table.refresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.typeSelect = ''
      this.$refs.table.refresh(true)
    },
    handleButtonSelectChange(e) {
      this.$refs.table.refresh(true)
    },
    handleDetailEdit(id) {
      localStorage.setItem('browserCacheEdit', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'primaryAuditManagementDetailEdit',
        params: {
          id,
        },
      })
    },
    handleDetail(id) {
      localStorage.setItem('browserCacheDetail', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'primaryAuditManagementDetail',
        params: {
          id,
        },
      })
    },
    handleAudit(id) {
      this.$router.push({
        name: 'primaryAuditManagementAudit',
        params: {
          id,
          type: 'community',
        },
      })
    },
    handlePrint(record) {
      this.printData = record
      this.visiblePrint = true
    },
  },
}
</script>
<style lang="less" scoped>
.table-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
/deep/ .ant-table td {
  white-space: nowrap;
}
</style>
